﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MvcMall.AdminWeb.DtoModels;
using MvcMall.Core.Contacts.Tasks;
using MvcMall.Framework.MvcPager;

namespace MvcMall.AdminWeb.Manage.User
{
    public partial class UserList : ManageBasePage
    {
        private IUserTask _userTask;

        protected void Page_Load(object sender, EventArgs e)
        {
            ValidatePagePower("UserManager");
            _userTask = GetInstance<IUserTask>();
            if (!IsPostBack)
            {
                Bind();
            }
        }

        protected void ANPager_PageChanged(object sender, EventArgs e)
        {
            Bind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Bind();
        }


        protected void Bind()
        {
            var list = _userTask.GetPagedList(txtUserName.Text.Trim(), txtRealName.Text.Trim(), txtEmail.Text.Trim(), txtTel.Text.Trim(), txtPhone.Text.Trim(), int.Parse(ddlSex.SelectedValue), ANPager.CurrentPageIndex, ANPager.PageSize);
            var dtoList = list.Select(m => new UserDto
            {
                Id = m.Id, Birthday=m.Birthday, Email=m.Email, EmailCheckCode=m.EmailCheckCode, EmailChecked=m.EmailChecked, IsLocked=m.IsLocked, Mobile=m.Mobile, Password=m.Password, Phone=m.Phone, QQ=m.QQ, RealName=m.RealName, RealNameChecked=m.RealNameChecked, RegTime=m.RegTime, Sex=m.Sex, UserHeaderImage=m.UserHeaderImage, UserName=m.UserName
            
            }).ToPagedList(ANPager.CurrentPageIndex, ANPager.PageSize, list.TotalItemCount);
            rptList.DataSource = dtoList;
            rptList.DataBind();
            ANPager.RecordCount = dtoList.TotalItemCount;
        }
    }
}